<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内容显示隐藏</title>
    <link rel="stylesheet" href="./index.css">
    <style>
        .case1 .active {
            display: none;
        }
    </style>
</head>
<body>
    <div class="case1">
        <h1>案例一：控制内容显示隐藏</h1>
        <div class="content">
            hello world
        </div>
        <button>显示/隐藏</button>
    </div>
    <script>
        // 案例一：控制显示隐藏
        let content = document.querySelector(".case1 .content")
        let case1Btn = document.querySelector(".case1 button")
        // 方法一：通过行内样式控制
        // case1Btn.addEventListener("click", ()=>{
        //     if(content.style.display == "block"||content.style.display == ""){
        //         content.style.display = "none"
        //     }else{
        //         content.style.display = "block"
        //     }
        // })
        // 方法二：通过类名active控制
        case1Btn.addEventListener("click", ()=>{
            // content.classList.toggle("active")
            let bool = content.classList.contains("active")
            if(bool){
                content.classList.remove("active")
            }else{
                content.classList.add("active")
            }
        })
    </script>
</body>
</html>